define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'recharge/index',
                    add_url: 'recharge/add',
                    edit_url: 'recharge/edit',
                    del_url: 'recharge/del',
                    multi_url: 'recharge/multi',
                    alipay_url: 'alipay/index',
                    table: 'recharge',
                }
            });

            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'out_trade_no', title: __('Out_trade_no')},
                        {field: 'admin.company.title', title: __('商家')},
                        {field: 'admin.username', title: __('Admin.username')},
                        {field: 'money', title: __('Money'), operate: 'BETWEEN'},
                        {field: 'pay_type', title: __('Pay_type')},
                        {field: 'update_time', sortable: true,
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange'},
                    ]
                ],
                queryParams: function (params) {
                    //这里可以追加搜索条件
                    var filter = JSON.parse(params.filter);
                    var op = JSON.parse(params.op);
                    //这里可以动态赋值，比如从URL中获取admin_id的值，filter.admin_id=Fast.api.query('admin_id');
                    filter.status = 'complete';
                    op.status = "=";
                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                },
            });

            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                //这里我们手动设置底部的值
                $("#total_wechat").text(data.total_wechat);
                $("#total_alipay").text(data.total_alipay);

            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            // $("form").submit(function (e) {
            //     event.preventDefault();
            //     return false;
            // });
            $(".btn-experience").on("click", function () {
                location.href = "/admin.php/" + $("input[name=pay_type]:checked").val() + "/index?amount=" + $("input[name=amount]").val()+ "&admin_id=" + $("input[name=admin_id]").val();
                return false;
            });
            Controller.api.bindevent();
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});